package net.sunzc.takephoto.utils;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

/**
 * Created by Administrator on 2017/1/6.
 */
public abstract class ProgressAsyncTask<T, P> extends AsyncTask<T, Integer, P> {
    protected Context context;
    private ProgressDialog progressBar;

    protected ProgressAsyncTask(Context context) {
        if (context == null) return;
        this.context = context;
        progressBar = new ProgressDialog(context);
        progressBar.setTitle("开始提取图片集模板...");
        progressBar.setCanceledOnTouchOutside(false);
        progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    }

    protected ProgressDialog getProgressBar() {
        return progressBar;
    }

    @Override
    protected void onPreExecute() {
        progressBar.show();
    }

    @Override
    protected void onProgressUpdate(Integer[] values) {
        progressBar.setProgress(values[0]);
    }

    @Override
    protected void onPostExecute(P p) {
        progressBar.dismiss();
    }
}
